<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <!-- <el-form-item label="状态" prop="title">
       <el-select
          v-model="queryParams.status"
          placeholder="状态"
          clearable
        >
          <el-option
            label="即将到期"
            value="1"
          />
          <el-option
            label="已到期"
            value="2"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="车牌号" prop="licenseNum">
        <el-input
          v-model="queryParams.licenseNum"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['vehicle:checkUp:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @selection-change="handleSelectionChange"
      fit
      v-loading="loading"
      border
      :data="dataList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" />
      <el-table-column
        :show-overflow-tooltip="true"
        label="车牌号"
        prop="licenseNum"
      />
      <el-table-column
        :show-overflow-tooltip="true"
        label="品牌类型"
        prop="brand"
      />
      <el-table-column :show-overflow-tooltip="true" label="车辆类型">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_driver_type"
            :value="scope.row.driverTypeValue"
          />
        </template>
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        label="驾驶员"
        prop="nickName"
      />
      <el-table-column
        show-overflow-tooltip
        width="150"
        label="注册日期"
        prop="checkDate"
      >
        <template slot-scope="scope">
          {{ parseTime(scope.row.carInfo.yearCheckDate, "{y}-{m}-{d}") }}
        </template>
      </el-table-column>
      <!-- <el-table-column
        show-overflow-tooltip
        width="150"
        label="年检日期"
        prop="nextYearCheckDate"
      >
        <template slot-scope="scope">
          {{ parseTime(scope.row.carInfoBo.nextYearCheckDate, "{y}-{m}-{d}") }}
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="status" ></el-table-column> -->
      <!-- <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
        fixed="right"
      >
        <template slot-scope="scope">
       
          <el-button
          v-if="scope.row.status=='即将到期'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['vehicle:checkUp:edit']"
            >已年检</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listCarYearCheckNew, delCarYearCheck } from "@/api/car/carYearCheck.js";

export default {
  name: "checkUp",
  dicts: ["sys_driver_type"],

  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        operUserId: undefined,
        licenseNum: undefined,
        checkDate: null,
      },
      // 日期范围
      dateRange: [],

      userList: [],
      deptOptions: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.carYearCheckId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      const configId = row.carYearCheckId || this.ids;
      this.$router.push("./addCheckUp?isEdit=true&id=" + configId);
    },
    handleDetail(row) {
      this.$router.push("./addCheckUp?isInfo=true&id=" + row.carYearCheckId);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.carYearCheckId || this.ids;
      let name = this.checkRow(
        configId,
        this.dataList,
        "carYearCheckId",
        "DELETE",
        "licenseNum"
      );
      this.$modal
        .confirm('是否确认删除车牌号为"' + name + '"的数据项？')
        .then(function () {
          return delCarYearCheck(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleAdd() {
      this.$router.push("./addCheckUp");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listCarYearCheckNew(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startEndDate",
          "endEndDate"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleExport() {
      this.download(
        "system/carYearCheck/export",
        {
          ...this.queryParams,
        },
        `车辆年检记录表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
